/* GLWindow.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <graphics/GLTextureManager.h>
#include <graphics/GLWindow.h>
#include <utils/GLInfo.h>
#include <debug/logger.h>
#include <textures.h>

GLWindow::GLWindow(const char* title, unsigned int width, unsigned int height,
			unsigned int bpp, bool fullscreen)
	: SDLWindow(title, width, height, bpp, fullscreen), glScene(NULL)
{

}

GLWindow::GLWindow(const char* title, unsigned int width, unsigned int height,
			unsigned int bpp)
	: SDLWindow(title, width, height, bpp), glScene(NULL)
{

}

GLWindow::GLWindow(const char* title, unsigned int width, unsigned int height)
	: SDLWindow(title, width, height), glScene(NULL)
{

}

GLWindow::~GLWindow()
{
}

int
GLWindow::init()
{
	return SDLWindow::init();
}

int
GLWindow::setVideoMode()
{
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	return SDLWindow::setVideoMode();
}

int
GLWindow::updateVideoMode()
{
	return SDLWindow::updateVideoMode(SDL_OPENGL);
}

void
GLWindow::atLaunch()
{
	flogg(info) << "OpenGL v" << GLInfo::version() << logg::endl;
	flogg(info) << "OpenGL vendor: " << GLInfo::vendor() << logg::endl;
	flogg(info) << "OpenGL renderer: " << GLInfo::renderer() << logg::endl;
	flogg(info) << GLInfo::maxTextureUnits() << " texture units available and max. "
		<< GLInfo::maxVertexAttribs() << " vertex attributes." << logg::endl;
	GLTextureManager::getInstance().loadTextures();
}
void
GLWindow::callbackLoop()
{
	if (glScene != NULL)
	{
		glScene->draw();
		SDL_GL_SwapBuffers();
	}
}
